package com.walkline.dianping.dao;

import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;

import com.walkline.dianping.DianpingException;
import com.walkline.dianping.DianpingSDK;
import com.walkline.dianping.inf.Cities;
import com.walkline.util.Function;

public class DianpingCities extends DianpingObject implements Cities
{
	private String[] _cities;

	public DianpingCities(DianpingSDK dianping, JSONObject jsonObject) throws DianpingException
	{
		super(dianping, jsonObject);

		JSONArray jsonArray = _jsonObject.optJSONArray("cities");
		_cities = new String[jsonArray.length()];

		for (int i=0; i<jsonArray.length(); i++)
		{
			try {
				_cities[i] = jsonArray.get(i).toString();
			} catch (JSONException e) {Function.errorDialog(e.toString());}
		}
	}

	//本次API访问状态，如果成功返回"OK"，并返回结果字段，如果失败返回"ERROR"，并返回错误说明
	public String getStatus() {return _jsonObject.optString("status");}

	//支持商户搜索的最新城市列表
	public String[] getCities() {return _cities;}
}